package com.xiaozhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaozhi.entity.Discussion;
import com.xiaozhi.entity.Reply;
import com.xiaozhi.mapper.DiscussionMapper;
import com.xiaozhi.service.DiscussionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 烟尘
 * @since 2023-03-15
 */
@Service
public class DiscussionServiceImpl extends ServiceImpl<DiscussionMapper, Discussion> implements DiscussionService {

    @Autowired
    private DiscussionMapper discussionMapper;

    private final int TOP_SIZE=5;
    @Override
    public List<Discussion> getAllByCondition(String text) {
        return discussionMapper.searchdis(text);
    }

    @Override
    public List<Discussion> getAllByTop() {
        List<Discussion> allByTop = discussionMapper.getAllByTop();
        List<Discussion> results=new ArrayList<>();
        for(int i=0;i<TOP_SIZE;i++){
            results.add(allByTop.get(i));
        }
        return results;
    }

    @Override
    public List<Discussion> getAllByRecommend() {
        List<Discussion> allByRecommend = discussionMapper.getAllByRecommend();
        Random random=new Random();
        HashSet<Integer> set=new HashSet<>();
        while (set.size()<10){
            set.add(random.nextInt(25));
        }
        Iterator<Integer> iterator = set.iterator();
        List<Discussion> results=new ArrayList<>();
        while (iterator.hasNext()){
            results.add(allByRecommend.get(iterator.next()));
        }
        return results;
    }

    @Override
    public Discussion getAllMes(Integer id) {
       return discussionMapper.getDisAndRep(id);
    }




}
